package com.app.teaware.common;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.app.teaware.R;
import com.app.teaware.basis.BasisActivity;
import com.app.teaware.bean.ProjectFileData;
import com.app.teaware.bean.ProjectFileListBean;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import my.ActivityTool;

public class AdapterFileList extends RecyclerView.Adapter<AdapterFileList.ViewHolder> {
    ProjectFileListBean mListBean;
    BasisActivity mContext;

        public AdapterFileList(BasisActivity context, ProjectFileListBean listBean) {
            mContext = context;
            mListBean = listBean;
        }

        //创建新View，被LayoutManager所调用
        @Override
        public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
            View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.notice_detail_view_file_list_item, viewGroup, false);
            return new ViewHolder(view);
        }


        //将数据与界面进行绑定的操作
        @Override
        public void onBindViewHolder(ViewHolder viewHolder, int position) {
            viewHolder.bind(position);
        }

        //获取数据的数量
        @Override
        public int getItemCount() {
            return mListBean == null ? 0 : mListBean.getList().size();
        }

        //自定义的ViewHolder，持有每个Item的的所有界面元素
        public class ViewHolder extends RecyclerView.ViewHolder {
            @BindView(R.id.list_item)
            public View list_item;
            @BindView(R.id.text_name)
            public TextView text_name;
            @BindView(R.id.img_icon)
            public ImageView img_icon;

            public ViewHolder(View view) {
                super(view);
                ButterKnife.bind(this, view);
            }

            public void bind(int position){
                ProjectFileData data = mListBean.getList().get(position);
//                list_item.setTag(position);
                text_name.setText(data.getFileName());
//                img_icon.setImageResource(data.getImgresByname());

                list_item.setTag(position);

            }

            @OnClick(R.id.list_item)
            public void viewDetail(View v) {
                int position =  (int) v.getTag();
                ProjectFileData data = mListBean.getList().get(position);
                Bundle extras = new Bundle();
                extras.putSerializable("data",data);
                extras.putString("title","查看文件");
                ActivityTool.skipActivity( mContext,ViewFileDetailActivity.class,extras);
            }
        }
    }